package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Order;
import com.itheima.reggie.domain.OrderDetail;
import com.itheima.reggie.domain.SetmealDish;
import com.itheima.reggie.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
public class OrderController {
    @Autowired
    private OrderService orderService;

    @Autowired
    private HttpSession session;

    //支付功能
    @PostMapping("/order/submit")
    public ResultInfo submits(@RequestBody Order order){
        orderService.submits(order);
        return ResultInfo.success(null);
    }

    //查看订单
    @GetMapping("/order/userPage")
    public ResultInfo findPage(@RequestParam(value = "page",defaultValue = "1") Integer pageNum,
                               @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize){
        Page<Order> page = orderService.findPage(pageNum,pageSize);
        return ResultInfo.success(page);
    }

    //退出登录
    @PostMapping("/user/logout")
    public ResultInfo logout(){
        //清空session信息
        session.invalidate();
        //返回成功信息
        return ResultInfo.success(null);
    }

    //根据套餐id查询
    @GetMapping("/setmeal/dish/{id}")
    public ResultInfo findDish(@PathVariable("id") Long id){
        List<SetmealDish> setmealDishes = orderService.findDish(id);
        return ResultInfo.success(setmealDishes);
    }
}
